<template>
  <div class="app-container">
    <el-radio-group v-model="listQuery.status" style="margin-bottom: 30px;">
      <el-radio-button label="0">待审核</el-radio-button>
      <el-radio-button label="1">已通过</el-radio-button>
      <el-radio-button label="2">已拒绝</el-radio-button>
    </el-radio-group>
    <div class="filter-container">

      <el-input
        v-model="listQuery.user_phone"
        size="small"
        placeholder="请输入手机"
        clearable
        class="filter-item w-200"
      />

      <el-select
        v-model="listQuery.verify_type"
        size="small"
        placeholder="选择认证类型"
        clearable
        class="filter-item"
      >
        <el-option label="所有" :value="0"/>
        <el-option label="机构认证" :value="2"/>
        <el-option label="企业认证" :value="4"/>
      </el-select>
      <el-button-group class="filter-item">
        <el-button
          size="small"
          type="primary"
          icon="el-icon-search"
          @click="search"
        >
          搜索
        </el-button>
        <el-button
          size="small"
          type="primary"
          icon="el-icon-refresh"
          @click="refresh"
        >
          重置
        </el-button>

      </el-button-group>
    </div>

    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      height="100%"
      class="table-container"
      highlight-current-row
    >
      <el-table-column
        fixed
        label="认证名称"
        width="140"
        align="center"
      >
        <template slot-scope="scope">
          {{ scope.row.user_name }}
        </template>
      </el-table-column>

      <el-table-column
        fixed
        label="认证类型"
        width="100"
        align="center"
      >
        <template slot-scope="scope">
          {{ scope.row.verify_type == 2 ? '机构认证' : '企业认证' }}
        </template>
      </el-table-column>

      <el-table-column
        label="认证资料"
        width="250"
        align="center"
      >
        <template slot-scope="scope">
          {{ scope.row.verify_profile }}
        </template>
      </el-table-column>

      <el-table-column
        label="附加资料"
        width="400"
        align="center"
      >
        <template slot-scope="scope">
          <el-image
            style="width: 60px; height: 60px;object-fit: cover;margin-right:10px;"
            :src="item.url"
            v-for="(item,idx) in scope.row.verify_img"
            :preview-src-list="all(scope.row.verify_img)"
          >
          </el-image>
        </template>
      </el-table-column>


      <el-table-column
        width="130"
        label="运营人姓名"
        align="center"
      >
        <template slot-scope="scope">
          {{ scope.row.user_name }}
        </template>
      </el-table-column>


      <el-table-column
        label="手机"
        width="110"
        align="center"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.user_phone }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="qq"
        width="110"
        align="center"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.user_qq }}</span>
        </template>
      </el-table-column>


      <el-table-column
        label="部门及职务"
        width="160"
        align="center"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.user_bumen }}</span>
        </template>
      </el-table-column>


      <el-table-column
        label="操作"
        width="230"
        align="center"
        v-if="listQuery.status==0"
      >
        <template slot-scope="scope">
          <el-button-group>
            <el-button
              type="primary"
              size="mini"
              @click="yes(scope.row.id)"
            >
              通过审核
            </el-button>

            <el-button
              type="danger"
              size="mini"
              @click="no(scope.row.id)"
            >
              拒绝
            </el-button>

          </el-button-group>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="fetchData"
    />


  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
import { getVerifyList,actionVerify } from '@/api/user'

const _temp = {
  id: '',
  username: '',
  truename: '',
  role: [],
  type: '管理员',
  email: '',
  status: 1
}

export default {
  components: {
    Pagination
  },
  data() {
    return {
      total: 0,
      list: [],
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        user_phone: '',
        verify_type: '',
        status:'0'
      },
      temp: Object.assign({}, _temp),
      dialogVisible: false,
      dialogType: 'create',
      loading: false
    }
  },
  created() {
    this.fetchData()
  },
  watch: {
    'listQuery.status': function (n) {
      this.fetchData()
    }
  },
  methods: {
    all(imgary){
      return imgary.map(item=>item.url)
    },
    no(id) {
      this.$prompt('请输入拒绝理由', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputValue: ''
      }).then(({ value }) => {
        this.loading = true
        actionVerify({ id:id, action: 'no', status_msg: value }).then(r => {
          this.fetchData()
        }, data => {
        })
      }).catch(() => {
      })
    },
    yes(id) {
      this.$confirm('是否通过审核，该操作不可逆', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        actionVerify({ id:id, action: 'yes' }).then(r => {
          this.fetchData()
        }, data => {
        })
      }).catch(() => {
      })
    },
    search() {
      this.fetchData()
    },
    refresh() {
      this.listQuery = {
        page: 1,
        limit: 20,
        created_at: undefined,
        status: undefined,
        keyword: undefined
      }
      this.fetchData()
    },
    fetchData() {
      this.listLoading = true
      getVerifyList(this.listQuery).then(response => {
        this.list = response.data.data
        this.total = response.data.total
        this.listLoading = false
      })
    },
    resetTemp() {
      this.temp = Object.assign({}, _temp)
    }

  }
}
</script>
